Skip to content

refactor: introduce SshCommandCoordinator — coordinator owns I/O, service handler delegates#4

Merged
gensyn merged 2 commits intomainfrom
copilot/evaluate-ssh-coordinator-usage
Mar 16, 2026
Merged

refactor: introduce SshCommandCoordinator — coordinator owns I/O, service handler delegates#4
gensyn merged 2 commits intomainfrom
copilot/evaluate-ssh-coordinator-usage

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 16, 2026

The execute service handler in __init__.py was performing all SSH I/O inline, violating the standard HA pattern where a coordinator owns I/O and callers are pure dispatchers.

Changes

coordinator.py (new)

  • SshCommandCoordinator owns all SSH I/O for the integration
  • async_execute(data) — connection, command execution, and error mapping
  • _resolve_known_hosts(...) — moved from __init__.py

__init__.py

  • async_setup_entry creates SshCommandCoordinator(hass) and stores it at hass.data[DOMAIN][entry.entry_id]
  • async_unload_entry removes it
  • Service handler validates input, then delegates:
# Before: inline SSH I/O
async with connect(**conn_kwargs) as conn:
    result = await conn.run(**run_kwargs)
return {CONF_OUTPUT: result.stdout, ...}

# After: delegate to coordinator
coordinator = next(iter(hass.data.get(DOMAIN, {}).values()), None)
return await coordinator.async_execute(service_call.data)

Tests

  • test_async_execute.py — patches updated to ssh_command.coordinator.*; asyncSetUp now calls async_setup_entry to wire up the coordinator
  • test_async_setup.py — added assertions for coordinator creation/removal
  • test/test_coordinator.py (new) — unit tests for async_execute error paths and _resolve_known_hosts
Original prompt

This section details on the original issue you should resolve

<issue_title>Should a coordinator be used for SSH calls?</issue_title>
<issue_description>Have look at this PR for SSH Docker and tell me whether the changes made there make sense for this repository as well:

gensyn/ssh_docker#18</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

…vice handler delegates

Co-authored-by: gensyn <36128035+gensyn@users.noreply.github.com>
Copilot AI changed the title [WIP] Discuss coordinator use for SSH calls refactor: introduce SshCommandCoordinator — coordinator owns I/O, service handler delegates Mar 16, 2026
Copilot AI requested a review from gensyn March 16, 2026 11:29
@gensyn gensyn marked this pull request as ready for review March 16, 2026 11:48
@gensyn gensyn merged commit dfbbd7f into main Mar 16, 2026
6 checks passed
@gensyn gensyn deleted the copilot/evaluate-ssh-coordinator-usage branch March 17, 2026 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Should a coordinator be used for SSH calls?

2 participants